package com.ruoyi.web.controller.miniprogram;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.system.SysPintuanOrder;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.service.ISysPintuanOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 小程序拼团订单Controller
 *
 * @author zjw
 * @date 2023-08-15
 */
@RestController
@RequestMapping("/system/pintuanorder")
public class SysPintuanOrderController extends BaseController {
    @Autowired
    private ISysPintuanOrderService sysPintuanOrderService;

    /**
     * 查询小程序拼团订单列表
     */
    @PreAuthorize("@ss.hasPermi('system:order:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysPintuanOrder sysPintuanOrder) {
        startPage();
        List<SysPintuanOrder> list = sysPintuanOrderService.selectSysPintuanOrderList(sysPintuanOrder);
        return getDataTable(list);
    }

    /**
     * 导出小程序拼团订单列表
     */
    @PreAuthorize("@ss.hasPermi('system:order:export')")
    @Log(title = "小程序拼团订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysPintuanOrder sysPintuanOrder) {
        List<SysPintuanOrder> list = sysPintuanOrderService.selectSysPintuanOrderList(sysPintuanOrder);
        ExcelUtil<SysPintuanOrder> util = new ExcelUtil<SysPintuanOrder>(SysPintuanOrder.class);
        util.exportExcel(response, list, "小程序拼团订单数据");
    }

    /**
     * 获取小程序拼团订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:order:query')")
    @GetMapping(value = "/{pintuanOrderId}")
    public AjaxResult getInfo(@PathVariable("pintuanOrderId") Long pintuanOrderId) {
        return success(sysPintuanOrderService.selectSysPintuanOrderByPintuanOrderId(pintuanOrderId));
    }

    /**
     * 新增小程序拼团订单
     */
    @PreAuthorize("@ss.hasPermi('system:order:add')")
    @Log(title = "小程序拼团订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysPintuanOrder sysPintuanOrder) {
        return toAjax(sysPintuanOrderService.insertSysPintuanOrder(sysPintuanOrder));
    }

    /**
     * 修改小程序拼团订单
     */
    @PreAuthorize("@ss.hasPermi('system:order:edit')")
    @Log(title = "小程序拼团订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysPintuanOrder sysPintuanOrder) {
        return toAjax(sysPintuanOrderService.updateSysPintuanOrder(sysPintuanOrder));
    }

    /**
     * 删除小程序拼团订单
     */
    @PreAuthorize("@ss.hasPermi('system:order:remove')")
    @Log(title = "小程序拼团订单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{pintuanOrderIds}")
    public AjaxResult remove(@PathVariable Long[] pintuanOrderIds) {
        return toAjax(sysPintuanOrderService.deleteSysPintuanOrderByPintuanOrderIds(pintuanOrderIds));
    }
}
